/*
 * Copyright (c) 2017 Qunar.com. All Rights Reserved.
 */
package com.guoyu.project.web.api;

import com.guoyu.project.model.Province;
import com.guoyu.project.model.School;
import com.guoyu.project.service.ProvinceService;
import com.guoyu.project.service.SchoolService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.guoyu.project.common.web.APIResponse;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: libo Date: 17-6-26 Time: 上午11:22
 * @version: \$Id$
 */
@Controller
@RequestMapping("api/province")
public class ProvinceApiService {

    @Resource
    private ProvinceService provinceService;
    @Resource
    private SchoolService schoolService;

    @RequestMapping("all")
    @ResponseBody
    public APIResponse all() {
        List<Province> provinceList = provinceService.queryAll();
        return APIResponse.returnSuccess(provinceList);
    }

    @RequestMapping("info")
    @ResponseBody
    public APIResponse info(@RequestParam(defaultValue = "0") int provinceId) {
        Province province = provinceService.queryById(provinceId);
        return APIResponse.returnSuccess(province);
    }

    @RequestMapping("school")
    @ResponseBody
    public APIResponse school(@RequestParam(defaultValue = "0") int provinceId) {
        List<School> schoolList = schoolService.queryByProvince(provinceId);
        return APIResponse.returnSuccess(schoolList);
    }

}
